from Pymacs import lisp
interactions = {}

def hello_world():
    content = "Hello from Python!"
    lisp.insert(content)

interactions[hello_world] = ''
    
def hi_world(greet, type):
    print greet
    lisp.insert(greet)
    lisp.insert(chr(type))

interactions[hi_world] = 'sGreeting contents?\nctype?'

def insert_node(name, type):
    lisp.insert("@node " + name + "\n")
    type = chr(type)
    tp = ""
    if type == '1':
        tp = "chapter"
    elif type == '2':
        tp = "section"
    elif type == '3':
        tp = "subsection"
    elif type == '4':
        tp = "subsubsection"
    else:
        tp = "node"
    lisp.insert("@" + tp + " " + name)

interactions[insert_node] = "sNode name?\ncNode type?"

def doxy_hdr(params):
    """insert doxygen header"""
    lisp.insert("/**\n * \\brief \n")
    num = params - ord('0')
    while num > 0:
        lisp.insert(" * \\param[in] \n")
        num -= 1
    lisp.insert(" * \\param[out] \n */")

interactions[doxy_hdr] = "cParam num?"

def datetime():
    """insert current datetime"""
    import datetime
    lisp.insert(datetime.datetime.now().ctime())

interactions[datetime] = ''

def dt_node(type):
    """insert current datetime as node"""
    import datetime
    name = datetime.datetime.now().ctime()
    insert_node(name, type)

interactions[dt_node] = "cNode type?"    

def encrypt(key, src):
    """ encrypt string """
    from Crypto.Cipher import AES
    enc = AES.new(key, AES.MODE_CBC)
    fill = (16 - len(src) % 16) * ' '
    return enc.encrypt(src + fill)

interactions[encrypt] = "sKey?\nsSrc?"
